#include "StdAfx.h"
#include ".\node.h"

CNode::CNode(void):
m_pParent(NULL),
m_vScale(1,1,1)
{
	m_bLightEnable[0] = TRUE;
	for (int i = 1; i < LIGHT_COUNT; i++)
	{
		m_bLightEnable[i] = FALSE;
	}
}

CNode::~CNode(void)
{
	vector<CTexture*>::iterator itTex = m_vTexture.begin();
	while (itTex != m_vTexture.end())
	{
		delete (*itTex);
		itTex++;
	}

	list<CNode*>::iterator itChild = m_listChild.begin();
	while (itChild != m_listChild.end())
	{
		delete (*itChild);
		itChild++;
	}
	m_listChild.clear();
}

void CNode::SetName(wstring strName)
{
	m_strName = strName;
}

void CNode::SetRotate(Vec3f vRot)
{
	m_vRot = vRot;
}

void CNode::SetScale(Vec3f vScale)
{
	m_vScale = vScale;
}

void CNode::SetTrans(Vec3f vTrans)
{
	m_vTrans = vTrans;
}

BOOL CNode::IsLightEnable(int nLightIdx)
{
	if (nLightIdx < 0 || nLightIdx >= LIGHT_COUNT) return FALSE;
	return m_bLightEnable[nLightIdx];
}

void CNode::SetLightEnable(BOOL bEnable, int nLightIdx)
{
	if (nLightIdx < 0 || nLightIdx >= LIGHT_COUNT) return;
	m_bLightEnable[nLightIdx] = bEnable;
}

BOOL CNode::AddChild(CNode* pNode)
{
	ASSERT(pNode);
	m_listChild.push_back(pNode);

	return TRUE;
}

BOOL CNode::AddTexture(wstring strFileName)
{
	CTexture* pTexture = new CTexture;
	if ( !pTexture->LoadTexture(strFileName) )
	{
		delete pTexture;
		return FALSE;
	}
	m_vTexture.push_back(pTexture);
	return TRUE;
}